![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
@jalik/observer
Advanced tools
Observe and emit events with ease.
Includes TypeScript declaration files.
The Observer design pattern is a well known pattern to create reactive applications. For example, your can attach observers to a form text field, then when the text field value changes, all observers are notified of that change and thus can do something in response.
The following code shows how to attach an observer and how to notify it of events.
import Observer from "@jalik/observer";
class Person {
constructor(name) {
this.name = name;
// Create the observer with current context
this.observer = new Observer(this);
}
on(event, observer) {
// Attach observer
this.observer.attach(event, observer);
}
say(words) {
// Notify observers
this.observer.notify("say", words, new Date());
}
}
const karl = new Person("karl");
karl.on("say", function (words, date) {
console.log(`${this.name} said: "${words}"`);
});
// this will show: karl said: "hello"
karl.say("hello");
In the case that you need to remove a previously attached observer, here is the code.
import Observer from "@jalik/observer";
const doubleClickListener = function () {
console.log("double click detected");
// This avoid the current function to be called
// on the next "doubleClick" event notification.
observer.detach("doubleClick", doubleClickListener);
};
const observer = new Observer();
observer.attach("doubleClick", doubleClickListener);
// This will call the doubleClickListener once.
observer.notify("doubleClick");
// This will not call the doubleClickListener
// since it has been detached in the previous call.
observer.notify("doubleClick");
History of releases is in the changelog.
The code is released under the MIT License.
If you find this lib useful and would like to support my work, donations are welcome :)
v1.2.1 (2023-04-14)
FAQs
A library to observe events and trigger callbacks.
We found that @jalik/observer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.